package com.hotelvip.controller;

import com.alibaba.fastjson.JSONObject;
import com.hotelvip.common.utils.EnumUtil;
import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.common.utils.RedisUtils;
import com.hotelvip.enumEntity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lzh
 * @date 2020/12/15 9:58
 */
@RestController
@Api(basePath = "/Enum",tags = "获取枚举api")
@RequestMapping("/Enum")
@Slf4j
public class EnumController {
    @ApiOperation(value = "NationEnum枚举",httpMethod = "GET")
    @GetMapping("/getNationEnum")
    public JSONResult getNationEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, NationEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, NationEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "AgeGroupEnum枚举",httpMethod = "GET")
    @GetMapping("/getAgeGroupEnum")
    public JSONResult getAgeGroupEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, AgeGroupEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, AgeGroupEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "CardStatueEnum枚举",httpMethod = "GET")
    @GetMapping("/getCardStatueEnum")
    public JSONResult getCardStatueEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 1;
        while (EnumUtil.getByindex(i, CardStatueEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, CardStatueEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "CszyEnum枚举",httpMethod = "GET")
    @GetMapping("/getCszyEnum")
    public JSONResult getCszyEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, CszyEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, CszyEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "FlagEnum枚举",httpMethod = "GET")
    @GetMapping("/getFlagEnum")
    public JSONResult getFlagEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, FlagEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, FlagEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "GenderEnum枚举",httpMethod = "GET")
    @GetMapping("/getGenderEnum")
    public JSONResult getGenderEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, GenderEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, GenderEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "IdentityEnum枚举",httpMethod = "GET")
    @GetMapping("/getIdentityEnum")
    public JSONResult getIdentityEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, IdentityEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, IdentityEnum.class).getName());
            map.put("parentId",EnumUtil.getByindex(i, IdentityEnum.class).getParentId());
            map.put("parentId",EnumUtil.getByindex(i, IdentityEnum.class).getIsParent());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "IdTypeEnum枚举",httpMethod = "GET")
    @GetMapping("/getIdTypeEnum")
    public JSONResult getIdTypeEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 1;
        while (EnumUtil.getByindex(i, IdTypeEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, IdTypeEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "IndustryEnum枚举",httpMethod = "GET")
    @GetMapping("/getIndustryEnum")
    public JSONResult getIndustryEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, IndustryEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, IndustryEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }

    @ApiOperation(value = "ItemStatueEnum枚举",httpMethod = "GET")
    @GetMapping("/getItemStatueEnum")
    public JSONResult getItemStatueEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 1;
        while (EnumUtil.getByindex(i, ItemStatueEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, ItemStatueEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "JobEnum枚举",httpMethod = "GET")
    @GetMapping("/getJobEnum")
    public JSONResult getJobEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, JobEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, JobEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "ZjxyEnum枚举",httpMethod = "GET")
    @GetMapping("/getZjxyEnum")
    public JSONResult getZjxyEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, ZjxyEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, ZjxyEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }
    @ApiOperation(value = "GenderEnum",httpMethod = "GET")
    @GetMapping("/getRegionEnum")
    public JSONResult getRegionEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, RegionEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, RegionEnum.class).getName());
            map.put("parentId",EnumUtil.getByindex(i, RegionEnum.class).getParentId());
            map.put("isParent",EnumUtil.getByindex(i, RegionEnum.class).getIsParent());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }


    @ApiOperation(value = "UserTypeEnum",httpMethod = "GET")
    @GetMapping("/getUserTypeEnum")
    public JSONResult getUserTypeEnum(){
        List<Map<String, Object>> list = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, UserTypeEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, UserTypeEnum.class).getName());
            list.add(map);
            i++;
        }
        return JSONResult.ok(list);

    }


    @ApiOperation(value = "All枚举",httpMethod = "GET")
    @GetMapping("/getAllEnum")
    public JSONResult getAllEnum(){
        HashMap<String, Object> enummap = new HashMap<>();
        RedisUtils redisUtils = new RedisUtils();
//        if (redisUtils.exist("ENUMALL")){
//            log.info("获取枚举 读取缓存");
//            String enumAll = redisUtils.get("ENUMALL");
//            Map jsonString = JSONObject.parseObject(enumAll, Map.class);
//            System.out.println();
//            return JSONResult.ok(jsonString);
//        }
        //遍历所有枚举
        List<Map<String, Object>> listNationEnum = new ArrayList<>();
        int i = 0;
        while (EnumUtil.getByindex(i, NationEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, NationEnum.class).getName());
            listNationEnum.add( map);
            i++;
        }
        List<Map<String, Object>> listAgeGroupEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, AgeGroupEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, AgeGroupEnum.class).getName());
            listAgeGroupEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listCardStatueEnum = new ArrayList<>();
        i = 1;
        while (EnumUtil.getByindex(i, CardStatueEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, CardStatueEnum.class).getName());
            listCardStatueEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listCszyEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, CszyEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, CszyEnum.class).getName());
            listCszyEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listFlagEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, FlagEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, FlagEnum.class).getName());
            listFlagEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listGenderEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, GenderEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, GenderEnum.class).getName());
            listGenderEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listIdentityEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, IdentityEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, IdentityEnum.class).getName());
            map.put("parentId",EnumUtil.getByindex(i, IdentityEnum.class).getParentId());
            map.put("isParent",EnumUtil.getByindex(i, IdentityEnum.class).getIsParent());
            listIdentityEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listIdTypeEnum = new ArrayList<>();
        i = 1;
        while (EnumUtil.getByindex(i, IdTypeEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, IdTypeEnum.class).getName());
            listIdTypeEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listIndustryEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, IndustryEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, IndustryEnum.class).getName());
            listIndustryEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listItemStatueEnum = new ArrayList<>();
        i = 1;
        while (EnumUtil.getByindex(i, ItemStatueEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, ItemStatueEnum.class).getName());
            listItemStatueEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listJobEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, JobEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, JobEnum.class).getName());
            listJobEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listZjxyEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, ZjxyEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, ZjxyEnum.class).getName());
            listZjxyEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listRegionEnum = new ArrayList<>();
        i = 1;
        while (EnumUtil.getByindex(i, RegionEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, RegionEnum.class).getName());
            map.put("parentId",EnumUtil.getByindex(i, RegionEnum.class).getParentId());
            map.put("isParent",EnumUtil.getByindex(i, RegionEnum.class).getIsParent());
            listRegionEnum.add(map);
            i++;
        }
        List<Map<String, Object>> listUserTypeEnum = new ArrayList<>();
        i = 0;
        while (EnumUtil.getByindex(i, UserTypeEnum.class)!=null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("index", i);
            map.put("name", EnumUtil.getByindex(i, UserTypeEnum.class).getName());
            listUserTypeEnum.add(map);
            i++;
        }


        //放入map
        enummap.put("NationEnum", listNationEnum);
        enummap.put("AgeGroupEnum", listAgeGroupEnum);
        enummap.put("CardStatueEnum", listCardStatueEnum);
        enummap.put("CszyEnum", listCszyEnum);
        enummap.put("FlagEnum", listFlagEnum);
        enummap.put("GenderEnum", listGenderEnum);
        enummap.put("IdentityEnum", listIdentityEnum);
        enummap.put("IdTypeEnum", listIdTypeEnum);
        enummap.put("IndustryEnum", listIndustryEnum);
        enummap.put("ItemStatueEnum", listItemStatueEnum);
        enummap.put("JobEnum", listJobEnum);
        enummap.put("ZjxyEnum", listZjxyEnum);
        enummap.put("RegionEnum", listRegionEnum);
        enummap.put("UserTypeEnum", listUserTypeEnum);
        redisUtils.set("ENUMALL", JSONObject.toJSONString(enummap));
        log.info("添加缓存成功");

        return JSONResult.ok(enummap);

    }
}
